package com.boot.multi.source.service.impl;

import com.boot.multi.source.domain.consumer.ConsumerUser;
import com.boot.multi.source.mapper.consumer.ConsumerUserMapper;
import com.boot.multi.source.service.ConsumerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 刘志强
 * @date 2020/11/27 14:20
 */
@Service
public class ConsumerUserImpl implements ConsumerUserService {

    @Autowired
    private ConsumerUserMapper consumerUserMapper;

    @Override
    public ConsumerUser getConsumerUser(Long id) {
        return consumerUserMapper.getConsumerUserById(id);
    }

    /**
     * @Transactional(rollbackFor = Exception.class,transactionManager="consumerTransactionManager")
     * consumerTransactionManager 消费者事务
     * @param consumerUser
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class,transactionManager="consumerTransactionManager")
    public String addConsumerUser(ConsumerUser consumerUser) {
        int i = consumerUserMapper.addConsumerUser(consumerUser);
        if ( i > 0 ) {
            return "添加成功";
        } else {
            return "添加失败";
        }
    }
}
